import requests

data_url = 'http://192.168.1.203:10000'

user = {
    "account": "admin1",
    "password": "1d15c27bbfde759f910dc1151502a200d2fd16250b8f408343668ee88d52011a8aedefa8a498fbbf7ac46de418033758969fe435a60d193b47a0af881f4eedd6aff4e2995981ec058b27dbd144e35834c0faf61647d409b0b790fb1690e3f9d27dbe00ac166799eddacf1f0e"
}


def login() -> str:
    response = requests.post(data_url + "/java/login", json=user)
    user_info = response.json()
    return get_cookie(str(user_info.get("data")))


def get_cookie(token: str):
    headers = {"Authorization": "Bearer " + token}
    print("token:", "Bearer " + token)

    r = requests.get(data_url + '/Account/LoginV2', headers=headers)
    cookie = r.history[0].headers.get('Set-Cookie')
    print("cookie='" + cookie + "'")
    return cookie


if __name__ == '__main__':
    login()
